package com.elinshaw;

import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;

import java.util.Map;

/**
 * Bolt数据过滤
 *
 * @author Administrator
 */
public class FirstBolt extends BaseRichBolt {

    /**
     * Bolt组件的Tuple发射器用于向下游Bole发射Tuple
     */
    private OutputCollector outputCollector;

    @Override
    public void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector) {
        this.outputCollector = outputCollector;
    }

    @Override
    public void execute(Tuple tuple) {
        //Tuple元组是一种kv结构用k取v
        Integer value = tuple.getIntegerByField("number");
        Values values = new Values(value);
        outputCollector.emit(values);
        // collector.ack(tuple);//处理完成要通知Storm
        //  collector.fail(tuple);//处理失败要通知Storm
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
        outputFieldsDeclarer.declare(new Fields("number"));
    }


}
